ihelpuoo.weboo.runtime.Runtime = function()
{
	this.modules = ihelpuoo.util.map();
	this.HTML = null;
	this.activeModule = null;
	
	this.NAME						= "runtime";
	this.URL_GET_MODULES			= "getModules";
	this.URL_GET_MODULEDETAIL		= "getModuleDetail";
	this.URL_GET_ACTIONS			= "getActions";
	this.URL_GET_ACTIONDETAIL		= "getActionDetail";
}

ihelpuoo.weboo.runtime.Runtime.prototype
=
{
	reload: function()
	{
		var xml =ihelpuoo.http.GETXML(ihelpuoo.http.server().url(this.NAME,this.URL_GET_MODULES));
		var root = xml.documentElement;
		this.valueOf(root);
	}
	
	,
	valueOf: function(ele)
	{
		this.modules.clear();
		var children = ele.getElementsByTagName("module");
		for(var i=0;i<children.length;i++)
		{
			var oM = children.item(i);
			var m = new ihelpuoo.weboo.runtime.Module();
			m.valueOf(oM);
			this.modules.put(m.name,m);
		}
	}

	,
	render: function()
	{
		if(null==this.HTML)
			this.HTML = new ihelpuoo.weboo.runtime.RuntimeHTML;
		this.HTML.clear();
		for(var key in this.modules.data)
		{
			var m = this.modules.get(key);
			var e = m.render();
			this.HTML.add(e);
		}
		return this.HTML.shell;
	}
	
	,
	getModule: function(name)
	{
		return this.modules.get(name);
	}
	
	,
	hasModule: function(name)
	{
		return this.modules.containsKey(name);
	}
	
	,
	setActiveModule: function(module)
	{
		var oldActiveModule = null;
		if(null!=this.activeModule && this.activeModule!=module)
			oldActiveModule = this.activeModule;
		this.activeModule = module;
		if(null!=oldActiveModule)
		{
			oldActiveModule.disactive();
		}
	}
	
	,
	isActiveModule: function(module)
	{
		if(null==this.activeModule) return false;
		if(null==module)return false;
		return this.activeModule==module;
	}
}

var ihelpuoo_weboo_runtime = null;
ihelpuoo.weboo.runtime.me = function()
{
	if(null==ihelpuoo_weboo_runtime)
	{
		ihelpuoo_weboo_runtime = new ihelpuoo.weboo.runtime.Runtime();
		ihelpuoo_weboo_runtime.reload();
	}	
	return ihelpuoo_weboo_runtime;
}